package cn.example.web.db.bean;

import lombok.experimental.Accessors;
import lombok.Data;
import lombok.AccessLevel;
import lombok.Setter;
import java.util.Date;
import org.artifact.core.db.BaseBean;
import org.artifact.core.lang.IServer;
import java.util.Map;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.map.MapUtil;
import java.util.HashMap;
@Data
@Accessors(chain = true)
@SuppressWarnings({"rawtypes","unchecked"})
/** 游戏码组 */
public abstract class GameCodeGroup implements BaseBean<GameCodeGroup> {
	/** 主键 */
	private long id;
	/** 类型 */
	private int type;
	/** 总次数 */
	private int totalUseCount;
	/** 单人次数 */
	private int singleUseCount;
	/** 状态 0.待激活 1.生效中 2.已失效 */
	private int status;
	/** 内容 */
	private java.util.HashMap body;
	/** 生效时间 */
	private java.util.Date effectiveDate;
	/** 失效时间 */
	private java.util.Date invalidDate;
	/** 专属渠道 */
	private int[] exclusiveChannel;
	/** 专属包 */
	private int[] exclusiveChannelApp;
	/** 专属平台 */
	private int[] exclusiveOs;
	/** 使用记录 */
	private java.util.HashMap useLog;
	/** 创建时间 */
	@Setter(value = AccessLevel.PROTECTED)
	private java.util.Date createDate;
	/** 修改时间 */
	@Setter(value = AccessLevel.PROTECTED)
	private java.util.Date modifiedDate;
	
	


	


	@Override
	public GameCodeGroup deepCopy() {
		GameCodeGroup gameCodeGroup = null;
		try {
			gameCodeGroup = (GameCodeGroup) super.clone();
			gameCodeGroup.body = (java.util.HashMap)this.body.clone();
			gameCodeGroup.effectiveDate = (java.util.Date)this.effectiveDate.clone();
			gameCodeGroup.invalidDate = (java.util.Date)this.invalidDate.clone();
			gameCodeGroup.useLog = (java.util.HashMap)this.useLog.clone();
			gameCodeGroup.createDate = (java.util.Date)this.createDate.clone();
			gameCodeGroup.modifiedDate = (java.util.Date)this.modifiedDate.clone();
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		onCopy(gameCodeGroup);
		return gameCodeGroup;
	}

	public <T extends GameCodeGroup> T build(GameCodeGroup t){
	    if(t == null) return null;
	    BeanUtil.copyProperties(t, this);
        onRead();
        return (T)this;
	}

	public GameCodeGroup toSave() {
        if(this.id == 0)
            this.id = (long)IServer.me().getContext().getIdFactory().getId();
		Date now = new Date();
		if (createDate==null) {
			createDate = now;
			modifiedDate = now;
		}else {
			modifiedDate = now;
		}
		onWrite();
		return deepCopy();
	}
	


    /**
     * 写数据
     */
    public Object write(){
        Object[] values = new Object[14];
        values[0] = this.id;
        values[1] = this.type;
        values[2] = this.totalUseCount;
        values[3] = this.singleUseCount;
        values[4] = this.status;
        values[5] = this.body;
        values[6] = this.effectiveDate;
        values[7] = this.invalidDate;
        values[8] = this.exclusiveChannel;
        values[9] = this.exclusiveChannelApp;
        values[10] = this.exclusiveOs;
        values[11] = this.useLog;
        values[12] = this.createDate;
        values[13] = this.modifiedDate;
        return values;
    }

    /**
     * 读数据
     */
    public GameCodeGroup read(Object object){
        Object[] array = (Object[])object;
        this.id = (long)array[0];
        this.type = (int)array[1];
        this.totalUseCount = (int)array[2];
        this.singleUseCount = (int)array[3];
        this.status = (int)array[4];
        this.body = (java.util.HashMap)array[5];
        this.effectiveDate = (java.util.Date)array[6];
        this.invalidDate = (java.util.Date)array[7];
        this.exclusiveChannel = (int[])array[8];
        this.exclusiveChannelApp = (int[])array[9];
        this.exclusiveOs = (int[])array[10];
        this.useLog = (java.util.HashMap)array[11];
        this.createDate = (java.util.Date)array[12];
        this.modifiedDate = (java.util.Date)array[13];
        return this;
    }
    /**
     * 克隆之后
     */
    protected void onCopy(GameCodeGroup gameCodeGroup){

    }

    /**
     * 写数据之前
     */
    protected void onWrite(){
    }

    /**
     * 读数据之后
     */
    protected void onRead(){
    }

	@Override
	public Object pk() {
		return this.id;
	}
}